<?php
class transaksibankpembeliancontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('transaksibankpembelian_model');
	}
	
	function index(){               
		if (isset($_POST['btnview'])) {
            if (isset($_POST['nofaktur'])) 
			{
				$nofaktur = $_POST['nofaktur'];
				$this->transaksibankpembelian_model->setNoFaktur($nofaktur);
				$dataprofile = array(
					'page_title' => 'Finance > Bank',
					'name' => $this->session->userdata('fullname'),
					'dt_faktur' => $this->transaksibankpembelian_model->getlistnofaktur(),
					'det_barang' => $this->transaksibankpembelian_model->getList(),
					'message'=>''
				);  
            }
        } 
		else 
		{
			$dataprofile = array(
				'page_title' => 'Finance > Bank',
				'name' => $this->session->userdata('fullname'),
				'dt_faktur' => $this->transaksibankpembelian_model->getlistnofaktur(),
				'det_barang' => $this->transaksibankpembelian_model->getList(),
				'message'=>''
			);		
		}
		$content = array(
			'content' => 'finance/bank/Transaksibankpembelian'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
	function simpan() {
        if (isset($_POST['btnSave'])) 
		{
			$query = $this->db->query("select max(NoKwitansi) nokwt from kwitansi");
        	$nokwi = $query->result();
        	$idkwitansi=(($nokwi[0]->nokwt) + 1);
			
			$this->transaksibankpembelian_model->setNoKwitansi($idkwitansi);
			$this->transaksibankpembelian_model->setNoFaktur($_POST['nofaktur1']);
			$this->transaksibankpembelian_model->setTotalQuantity($_POST['ttlqty']);
			$this->transaksibankpembelian_model->setDiscount($_POST['discount']);
			$this->transaksibankpembelian_model->setTotalAmount($_POST['ttlamount']);
			$this->transaksibankpembelian_model->setTypebayar($_POST['typebyr']);
			$this->transaksibankpembelian_model->setKodeBank($_POST['kdbank']);
			$this->transaksibankpembelian_model->setBankname($_POST['namabank']);
			$this->transaksibankpembelian_model->setNoRekening($_POST['norek']);
			$this->transaksibankpembelian_model->setKeterangan($_POST['keterangan']);
			$this->transaksibankpembelian_model->insert();

			redirect('Transaksibankpembelian');
        } else {
            $dataprofile = array(
				'page_title' => 'Finance > Bank',
				'name' => $this->session->userdata('fullname'),
				'dt_barang' => $this->transaksibankpembelian_model->getlistnofaktur(),
				'message'=>''		
			);		
		}
		
		$content = array(
		'content' => 'finance/bank/Transaksibankpembelian'
		);
		$this->template->load('templates/default',$content,$dataprofile);
    }
}